package com.lkd.controller;


import com.lkd.entity.Partner;
import com.lkd.service.PartnerService;
import com.lkd.vo.PageBean;
import com.lkd.vo.PartnerVo;
import com.lkd.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 合作商表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-20
 */
@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {

    @Autowired
    private PartnerService partnerService;

    //新增合作商
    @PostMapping
    public Boolean save(@RequestBody Partner partner){
        boolean save = partnerService.save(partner);
        return save;
    }

    //分页查询
    @GetMapping("search")
    public Result search(String name,
                         @RequestParam(defaultValue = "1")Integer pageIndex,
                         @RequestParam(defaultValue = "10")Integer pageSize){
       PageBean<PartnerVo> page=partnerService.search(name,pageIndex,pageSize);
       return Result.success(page);
    }

    //获取合作商详情
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer  id){
        PartnerVo partnerVo=partnerService.findById(id);
        return Result.success(partnerVo);
    }

    //修改合作商
    @PutMapping
    public Boolean update(@RequestBody Partner partner){
        boolean update = partnerService.updateById(partner);
        return update;
    }

    //删除合作商
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id){
        boolean removeById = partnerService.removeById(id);
        return removeById;
    }

    //合作商数量
    @GetMapping("/count")
    public Result count(){
        return Result.success(partnerService.count());
    }
}
